<?php

namespace App\Models;

use App\Enums\AvailableStatus;
use App\Enums\OngoingStatus;
use BenSampo\Enum\Traits\CastsEnums;

/**
 * @mixin IdeHelperLottery
 */
class Lottery extends BaseModel
{
    use CastsEnums;

    public const MAX_AWARD_COUNT = 6;

    protected $casts = [
        'status' => AvailableStatus::class,
        'start_time' => 'datetime',
        'end_time' => 'datetime',
    ];

    protected $appends = [
        'ongoing_status',
    ];

    public function awards()
    {
        return $this->hasMany(LotteryAward::class);
    }

    public function getOngoingStatusAttribute()
    {
        if (now()->lt($this->start_time)) {
            return OngoingStatus::NOT_START();
        }
        if (now()->gt($this->end_time)) {
            return OngoingStatus::FINISHED();
        }

        return OngoingStatus::ON_GOING();
    }
}
